import http, {HttpOptions} from "../http"

// 响应接口
export interface GetHousesByUserIdRes {
    code: number;
    msg: string;
    data: {
        id: number;
        householdId: number;
        householdLocal: string;
        houseName: string;
        houseRmake: string;
        updateBy: string;
        updateTime: string;
    }[];
    timestamp: number;
    now: string;
}

/**
 * 根据住户id获取房屋
 * @param {string} userId
 * @returns
 */
export function getHousesByUserId(userId: number): Promise<GetHousesByUserIdRes> {
    const config: HttpOptions = {
        msg: false,
        token: true,
        load: false,
    }
    return http.get(`/house/user/${userId}`,config);
}

// 响应接口
export interface DeleteHouseRes {}

/**
 * 删除房屋
 * @param {string} id
 * @returns
 */
export function deleteHouse(id: number): Promise<DeleteHouseRes> {
    const config: HttpOptions = {
        msg: false,
        token: true,
        load: false,
    }
    return http.delete(`/house/${id}`,config);
}

// 参数接口
export interface UpdateHouseParams {
    id?: number;
    householdId?: number;
    householdLocal?: string;
    houseName?: string;
    houseRmake?: string;
    updateBy?: string;
}

// 响应接口
export interface UpdateHouseRes {
    code: number;
    msg: string;
    data: Record<string, unknown>;
    timestamp: number;
    now: string;
}

/**
 * 修改房屋
 * @param {object} params 房屋信息实体类
 * @param {number} params.id 房屋唯一标识
 * @param {number} params.householdId 关联住户ID
 * @param {string} params.householdLocal 详细位置（格式：栋号-单元-房号）
 * @param {string} params.houseName 房屋别名
 * @param {string} params.houseRmake 备注信息
 * @param {string} params.updateBy 最后操作人
 * @returns
 */
export function updateHouse(params: UpdateHouseParams): Promise<UpdateHouseRes> {
    const config: HttpOptions = {
        msg: false,
        token: true,
        load: false,
    }
    return http.put(`/house`, params,config);
}

// 参数接口
export interface CreateHouseParams {
    id?: number;
    householdId?: number;
    householdLocal?: string;
    houseName?: string;
    houseRmake?: string;
    updateBy?: string;
}

// 响应接口
export interface CreateHouseRes {
    code: number;
    msg: string;
    data: Record<string, unknown>;
    timestamp: number;
    now: string;
}

/**
 * 新增房屋
 * @param {object} params 房屋信息实体类
 * @param {number} params.id 房屋唯一标识
 * @param {number} params.householdId 关联住户ID
 * @param {string} params.householdLocal 详细位置（格式：栋号-单元-房号）
 * @param {string} params.houseName 房屋别名
 * @param {string} params.houseRmake 备注信息
 * @param {string} params.updateBy 最后操作人
 * @returns
 */
export function createHouse(params: CreateHouseParams): Promise<CreateHouseRes> {
    const config: HttpOptions = {
        msg: false,
        token: true,
        load: false,
    }
    return http.post(`/house`, params,config);
}


// 参数接口
export interface GetHousePerParams {
    userId: number;
    houseId: number;
    aim: string;
    GuestNum: number;
    guestTime?: string;
    guestNum?: number;
}

// 响应接口
export interface GetHousePerRes {
    code: number;
    msg: string;
    data: string;
    timestamp: number;
    now: string;
}

/**
 * 获取房屋权限
 * @param {object} params HouseGuestDto
 * @param {number} params.userId 用户id
 * @param {number} params.houseId 房屋id
 * @param {string} params.aim 用途
 * @param {number} params.GuestNum 来访人数
 * @param {string} params.guestTime
 * @param {number} params.guestNum
 * @returns
 */
export function getHousePer(params: GetHousePerParams): Promise<GetHousePerRes> {
    const config:HttpOptions  = {
        msg: false,
        token: true,
        load: false,
    }
    return http.post(`/house/per`, params, config);
}